<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商品')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goods-add">
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label is-required">条码：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="barCode" class="form-control" type="text" required>-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">品牌：</label>
                <div class="col-sm-8">
                    <input name="brand" id="brand" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">款号：</label>
                <div class="col-sm-8">
                    <input name="styleNumber" id="styleNumber" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">商品名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" id="name" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">单位：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="unit" id="unit">
                        <option value="1">件</option>
                        <option value="2">套</option>
                        <option value="3">条</option>
                    </select>
                </div>
            </div>

<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">尺码：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="size" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">尺码：</label>
                <div class="col-sm-8">
                    <input name="size2" class="form-control" type="text">
                </div>
            </div>-->

            <div class="form-group">    
                <label class="col-sm-3 control-label">吊牌价：</label>
                <div class="col-sm-8">
                    <input name="tagPrice" id="tagPrice" class="form-control" value="0" type="number" required>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">进价：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="primeCost" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8">
                    <input id="filePath" name="filePath" class="form-control" type="file">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "goods/goods"
        $("#form-goods-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                uploadFile();
            }
        }

        function uploadFile() {
            //$.operate.save(prefix + "/add", $('#form-goods-add').serialize());
            var formData = new FormData();
            if ($('#filePath')[0].files[0] != null) {
                formData.append('fileName', $("#fileName").val());
                formData.append('file', $('#filePath')[0].files[0]);
            }
            formData.append('brand',$("#brand").val());
            formData.append('tagPrice',$("#tagPrice").val());
            formData.append('unit',$("#unit").val());
            formData.append('name',$("#name").val());
            formData.append('styleNumber',$("#styleNumber").val());

            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }

    </script>
</body>
</html>